package com.nf.health.app.activity.home;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.nf.health.app.R;
import com.nf.health.app.customview.CircleImageView;
import com.nf.health.app.glide.GlideUtil;
import com.nf.health.app.inquiry.docdetail.DocDetailActivity;
import com.nf.health.app.models.DoctorVo;
import com.nf.health.app.utils.ActivityUtils;
import com.nf.health.app.utils.DensityUtil;

/**
 *我的医生
 */

public class MyHomeDoctorLineaylayout  extends LinearLayout{
    public static String TYPE = "com.nf.type";
    private Activity context;
    private CircleImageView civ_doctor_header;
    private TextView tv_doctor_header;

    private LinearLayout ll_report_detail;
    private LayoutInflater inflater;
    private LinearLayout ll_doctor_header;

    public MyHomeDoctorLineaylayout(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView();
        regisitListener();
    }


    public MyHomeDoctorLineaylayout(Activity context) {
        super(context);
        this.context = context;
        initView();
        regisitListener();
    }

    private void regisitListener() {

    }
    private MyHomeDoctorLineaylayout initView() {
        inflater=(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view = inflater.inflate(R.layout.item_myhomedoctorlineay, this);
        tv_doctor_header  = (TextView) view.findViewById(R.id.tv_doctor_header);
        civ_doctor_header  = (CircleImageView) view.findViewById(R.id.civ_doctor_header);
        ll_doctor_header  = (LinearLayout) view.findViewById(R.id.ll_doctor_header);
        ViewGroup.LayoutParams params = ll_doctor_header.getLayoutParams();
        int perwidth =( DensityUtil.getScreenIntWidth(context))/ 4 ;
        params.width = perwidth;
        params.height = perwidth;
        ll_doctor_header.setLayoutParams(params);
        return this;
    }

    public MyHomeDoctorLineaylayout loadData(final DoctorVo doctorVo){

      /*  Glide.with(context)
                .load(doctorVo.getHimg())
                .placeholder(R.drawable.default_head)
                .into(civ_doctor_header);*/
        GlideUtil.loadNetImgC(context, civ_doctor_header, doctorVo.getHimg(), R.drawable.default_head);//设置医生头像
        String name = doctorVo.getDoctorname();
        if(TextUtils.isEmpty(name)){
            name = doctorVo.getNick();
        }
        tv_doctor_header.setText(name+"");
        ll_doctor_header.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {//跳转医生详情
                Bundle bundle = new Bundle();
                bundle.putString(DocDetailActivity.DOCTORID,doctorVo.getUserid());
                ActivityUtils.showActivity(context, DocDetailActivity.class, bundle);
            }
        });
        return this;
    }

}
